Coding1 -π Creating the Project Folder Structure
π§ What Youβll Learnβ
In this lesson, youβll set up the folder structure for your NodeJS RESTful API using:
- Node.js + Express
- TypeScript
- MongoDB (with Mongoose)
π§± Step 1: Initialize a New Projectβ
Open your terminal and run:
mkdir REST-API
cd REST-API
npm init -y
This creates your project folder and a basic package.json
file.
βοΈ Step 2: Install Required Dependenciesβ
Install these packages:
npm install express mongoose dotenv
npm install --save-dev typescript ts-node-dev @types/node @types/express @types/mongoose
π οΈ Step 3: Initialize TypeScriptβ
Run:
npx tsc --init
Then update your tsconfig.json
for better development experience:
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
}
}
π Step 4: Create Your Folder Structureβ
Inside the root directory, create a folder named src
:
mkdir src
cd src
mkdir controller model routes
touch app.ts dbconnect.ts
Your final folder structure should look like this:
REST-API/
βββ node_modules/
βββ src/
β βββ controller/ # All controller logic (e.g., auth.controller.ts)
β βββ model/ # Mongoose models (e.g., user.model.ts)
β βββ routes/ # All API route files (e.g., auth.routes.ts)
β βββ app.ts # Main application entry point
β βββ dbconnect.ts # MongoDB connection setup
βββ .env # Environment variables
βββ .gitignore
βββ package.json
βββ tsconfig.json
π‘ Bonus: Recommended .gitignore
β
Create a .gitignore
file and add:
node_modules/
dist/
.env
β Whatβs Next?β
In the next lesson, youβll:
- Connect your project to MongoDB
- Write the database setup logic in
dbconnect.ts